<template>
  <article class="p-3">
    <h4 class="word-break font-weight-normal">{{advisory.informationTitle}}</h4>
    <section>
      <p class="text-muted fz-12">{{$formatDateTime(advisory.ctime, 'zh')}}</p>
      <section>
        <div class="word-break article-img"  v-html="advisory.informationDetails"></div>
      </section>
    </section>

    <div class="d-flex justify-content-between">
      <div class="text-gray-500">
        阅读 {{advisory.browseNumber}}
      </div>
      <div class="text-tdsuccess">
        <img src="../../assets/dianzan2.png" class="img-responsive" style="width: 20px;position: relative;top: -3px;" alt="">
        <span class="mr-2">{{advisory.likeNumber}}</span>
      </div>
    </div>
    <!-- 评论展示区 -->
    <comments :info="advisory.coms" class="mt-5"></comments>
  </article>
</template>

<script>
import axios from 'axios'

let gen = async function (self) {
  let conpara = { informationId: self.$route.query.informationId }
  // 请求内容
  let res = await axios.post('/mscs/information/findInformationContentById', self.$paramsConvert(conpara))
  self.advisory = Object.assign(self.advisory, self.$route.query, res.data.data.data)
  self.advisory.ctime = parseInt(self.advisory.ctime)
  self.advisory.like = parseInt(res.data.data.like)
  self.advisory.likeNumber = parseInt(res.data.data.likeNumber)
  // 请求评论
  if (self.advisory.isComment === 'YES') {
    let comresUrl = '/mscs/information/findCommentByType'
    let comres = await axios.post(comresUrl, self.$paramsConvert({informationId: self.advisory.informationId}))
    self.advisory.coms = comres.data.data
  }
}

export default {
  name: "advisorydetails",
  title: "资讯详情",
  props: {
    // row: {}
  },
  data () {
    return {
      row: {},
      advisory: {
        likeNumber: 0,
        browseNumber: 0,
        coms: []
      }
    }
  },
  mounted () {
    // this.allGen()
  },
  methods: {
    allGen () {
      gen(this).then().catch((err) => {
        this.$catchError(err)
      })
    }
  },
  beforeRouteEnter (to, from, next) {
    next((vm) => {
      vm.allGen()
    })
  }
}
</script>
